package com.googlecode.continuity.plugin.gwtext.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.googlecode.continuity.plugin.gwtext.client.message.GWTExtensionMessages;

/**
 * The InformationBox provides a simple dialog which displays a message to the user .
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class InformationBox extends CenteredDialogBox {
  // message i18n
  private static final GWTExtensionMessages messages = (GWTExtensionMessages) GWT.create(GWTExtensionMessages.class);

  /**
   * Initializes a new information box with message.
   *
   * @param information the information to be presented to the user
   */
  public InformationBox(String information) {
    this(information, messages.ok());
  }

  /**
   * Initializes a new information box with message. Also lets you define button label.
   *
   * @param information the information to be presented to the user
   * @param label       button label
   */
  public InformationBox(String information, String label) {
    setText(messages.informationBoxHeader());

    Label informationLabel = new Label(information);
    frame.insert(informationLabel, frame.getWidgetIndex(buttons));

    Button ok = new Button(label, finished);
    buttons.add(ok);

    ok.setFocus(true);

    addStyleName("informationBox");
    informationLabel.addStyleName("information");

    frame.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
  }
}